<template>
	<view class="content">
		<view class="navigationBox">
			<image class="returnImg" src="../../static/img/return.png" mode="" @tap="go('../index/home')"></image>
			<view class="title">
				分校管理
			</view>
			<image class="addImg" src="../../static/img/add.png" mode="" @tap="go('../school/addSchool')"></image>
			<image class="searchImg" src="../../static/img/search.png" mode="" @tap="searchShow()">
			</image>
		</view>
		<view class="searchBox" v-if="searchShowStatus == true">
			<view class="pickerBox">
				<view class="iptBox pickerItem">
					<input class="ipt" type="text" placeholder="输入关键词" placeholder-class="iptPla"
						v-model="info.search_data">
					<view class="searchBtn" @tap="getSearch()">
						搜索
					</view>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list-box" v-for="(item,index) in list">
				<view class="school-data-box">
					<view class="school-data-title">机构名称</view>
					<view class="school-data">{{item.school_name}}</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">机构代码</view>
						<view class="school-data">{{item.school_code}}</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">代理级别</view>
						<view class="school-data" v-if="item.level == 1">总部</view>
						<view class="school-data" v-if="item.level == 2">省</view>
						<view class="school-data" v-if="item.level == 3">省会</view>
						<view class="school-data" v-if="item.level == 4">地级市</view>
						<view class="school-data" v-if="item.level == 5">区/县</view>
						<view class="school-data" v-if="item.level == 6">单店一</view>
						<view class="school-data" v-if="item.level == 7">单店二</view>
						<view class="school-data" v-if="item.level == 8">单店三</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">负责人</view>
						<view class="school-data">{{item.contact_name}}</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">手机号</view>
						<view class="school-data">{{item.contact_phone}}</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-left-box">
						<view class="school-data-title">机构状态</view>
						<view class="school-data-status-1" v-if="item.status == 1">待认证</view>
						<view class="school-data-status-2" v-if="item.status == 2">已认证</view>
						<view class="school-data-status-3" v-if="item.status == 3">正常</view>
						<view class="school-data-status-4" v-if="item.status == 4">待充值</view>
					</view>
					<view class="school-data-right-box">
						<view class="school-data-title">业务员</view>
						<view class="school-data">{{item.salesman}}</view>
					</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-title">剩余小时</view>
					<view class="school-data">{{item.left_module_hour}}小时</view>
				</view>
				<view class="school-data-box">
					<view class="school-data-title">所在区域</view>
					<view class="school-data">{{item.area}}</view>
				</view>
				<view class="log-btn-box">
					<view class="log-btn" @tap="goSchoolDetail(item.school_id)">详情查看</view>
					<view class="log-btn" @tap="goSchoolHourLog(item.school_id)">充值记录</view>
				</view>
				<view class="btn-box">
					<view class="authentication-btn" @tap="goSchoolAuthentication(item.school_id)">分校认证</view>
					<view class="recharge-btn" @tap="goRechargeSchool(item.school_id)">充值</view>
					<view class="deduction-btn" @tap="deductionSchool(item.school_id)">扣费</view>
					<view class="update-btn" @tap="goEditSchool(item.school_id)">编辑</view>
					<view class="delete-btn" @tap="deleteSchool(item.school_id)">删除</view>
				</view>
			</view>
		</view>
		<!-- 扣费弹框 -->
		<u-modal :show="deductionShow" @confirm="deductionConfirm" ref="uModal" :asyncClose="true"
			:showCancelButton="true" @cancel="deductionCancel">
			<view style="width: 100%;">
				<view class="item">
					<view class="label">
						扣费小时
					</view>
					<view class="ipt">
						<input type="text" placeholder="请输入扣费小时" v-model="deduction_module_minute">
					</view>
				</view>
			</view>
		</u-modal>
		<!-- 删除弹框 -->
		<u-modal :show="deleteShow" @confirm="deleteConfirm" ref="uModal" :asyncClose="true" :showCancelButton="true"
			@cancel="deleteCancel">
			<view style="width: 100%;text-align: center;">
				确认删除该分校信息吗？？
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deductionShow: false,
				deduction_module_minute: '',
				deduction_school_id: '',
				info: {
					search_data: '',
					page: 1,
					size: 10
				},
				list: [],
				searchShowStatus: false,
				pageSize: 10,
				pageTotal: 0,
				hasMore: true,
				delete_school_id: 0,
				deleteShow: false
			};
		},
		onLoad() {
			this.getData()
		},
		onReachBottom() {
			this.getData();
		},
		methods: {
			deductionSchool(school_id) {
				this.delete_school_id = school_id
				this.deductionShow = true
			},
			async deductionConfirm() {
				const {
					data: res
				} = await uni.$http.post('school/school/deductionSchool', {
					school_id: this.delete_school_id,
					module_minute: this.deduction_module_minute
				})
				if (res.code != 1) {
					this.deductionCancel()
					return this.toast.msg(res.msg)
				}
				this.deductionCancel()
				this.toast.msg('扣费成功')
				this.info.page = 1
				this.list = []
				this.getData();
			},
			deductionCancel() {
				this.deductionShow = false
				this.delete_school_id = ''
				this.deduction_module_minute = ''
			},
			searchShow() {
				if (this.searchShowStatus == false) {
					this.searchShowStatus = true;
				} else {
					this.searchShowStatus = false;
				}
			},
			getSearch() {
				this.info.page = 1
				this.list = []
				this.getData();
			},
			async getData() {
				uni.stopPullDownRefresh();
				const {
					data: res
				} = await uni.$http.post('school/school/getSchoolList', this.info)
				if (res.code != 1) {
					return this.toast.msg(res.msg)
				}

				if (res.data.data.length) {
					this.list = this.list.concat(res.data.data);
					this.info.page += 1;
				} else {
					this.toast.msg('没有更多数据了！')
				}
			},
			deleteSchool(school_id) {
				this.delete_school_id = school_id
				this.deleteShow = true
			},
			async deleteConfirm() {
				const {
					data: res
				} = await uni.$http.post('school/school/delSchool', {
					school_id: this.delete_school_id
				})
				if (res.code != 1) {
					this.deleteCancel()
					return this.toast.msg(res.msg)
				}
				this.toast.msg('删除成功')
				this.info.page = 1
				this.list = []
				this.getData();
				this.deleteCancel()
			},
			deleteCancel() {
				this.deleteShow = false
				this.delete_school_id = ''
			},
			goEditSchool(school_id) {
				uni.navigateTo({
					url: `/pages/school/editSchool?school_id=${school_id}`
				})
			},
			goSchoolDetail(school_id) {
				uni.navigateTo({
					url: `/pages/school/schoolDetail?school_id=${school_id}`
				})
			},
			goSchoolHourLog(school_id) {
				uni.navigateTo({
					url: `/pages/school/schoolHourLog?school_id=${school_id}`
				})
			},
			goSchoolAuthentication(school_id) {
				uni.navigateTo({
					url: `/pages/school/schoolAuthentication?school_id=${school_id}`
				})
			},
			goRechargeSchool(school_id) {
				uni.navigateTo({
					url: `/pages/school/rechargeSchool?school_id=${school_id}`
				})
			},
		}
	}
</script>

<style lang="scss">
	.btn-box {
		width: 100%;
		height: 46rpx;
		margin-top: 20rpx;
	}
	.authentication-btn {
		float: left;
		width: 20%;
		height: 46rpx;
		background: #EB9D50;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
	}
	.recharge-btn {
		float: left;
		width: 17%;
		height: 46rpx;
		background: #4E88E6;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
		margin-left: 3%;
	}
	.deduction-btn {
		float: left;
		width: 17%;
		height: 46rpx;
		background: #D43030;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
		margin-left: 3%;
	}
	.update-btn {
		float: left;
		width: 17%;
		height: 46rpx;
		background: #4E88E6;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
		margin-left: 3%;
	}
	.delete-btn {
		float: left;
		width: 17%;
		height: 46rpx;
		background: #D43030;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
		margin-left: 3%;
	}
	.log-btn-box {
		width: 40%;
		margin-left: 60%;
		height: 46rpx;
		margin-top: 20rpx;
	}
	.log-btn {
		float: left;
		width: 46%;
		height: 46rpx;
		background: #808080;
		font-size: 12px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		line-height: 46rpx;
		margin-left: 3%;
	}
	.school-data-box {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 26rpx;
		font-weight: 400;
	}

	.school-data-title {
		width: 130rpx;
		height: 50rpx;
		color: #333333;
		float: left;
	}

	.school-data {
		height: 50rpx;
		color: #666666;
		float: left;
	}

	.school-data-left-box {
		width: 50%;
		height: 50rpx;
		float: left;
	}

	.school-data-right-box {
		width: 50%;
		height: 50rpx;
		float: left;
	}

	.school-data-status-1 {
		width: 80rpx;
		height: 30rpx;
		border-radius: 10px;
		text-align: center;
		font-size: 20rpx;
		font-weight: 700;
		line-height: 30rpx;
		float: left;
		margin-top: 10rpx;
		background: #fab6b6;
		color: #fa3534;
	}

	.school-data-status-2 {
		width: 80rpx;
		height: 30rpx;
		border-radius: 10px;
		text-align: center;
		font-size: 20rpx;
		font-weight: 700;
		line-height: 30rpx;
		float: left;
		margin-top: 10rpx;
		background: #dbf1e1;
		color: #19be6b;
	}

	.school-data-status-3 {
		width: 80rpx;
		height: 30rpx;
		border-radius: 10px;
		text-align: center;
		font-size: 20rpx;
		font-weight: 700;
		line-height: 30rpx;
		float: left;
		margin-top: 10rpx;
		background: #F7EABE;
		color: #FFC300;
	}

	.school-data-status-4 {
		width: 80rpx;
		height: 30rpx;
		border-radius: 10px;
		text-align: center;
		font-size: 20rpx;
		font-weight: 700;
		line-height: 30rpx;
		float: left;
		margin-top: 10rpx;
		background: #a0cfff;
		color: #2979ff;
	}

	.content {
		.navigationBox {
			display: flex;
			align-items: center;
			height: 112rpx;
			padding: 50rpx 30rpx 0 51rpx;

			.returnImg {
				width: 52rpx;
				height: 52rpx;
			}

			.title {
				flex: 1;
				text-align: center;
			}

			.addImg {
				width: 23rpx;
				height: 23rpx;
			}

			.searchImg {
				width: 30rpx;
				height: 30rpx;
				margin-left: 30rpx;
			}
		}

		.searchBox {
			width: 670rpx;
			margin: 0 auto;
			padding: 0 20rpx;

			.pickerBox {
				font-size: 28rpx;
				height: 66rpx;
				line-height: 66rpx;
				display: flex;
				width: 100%;

				.pickerItem {
					display: flex;
					width: 100%;

					.frame {
						position: relative;
						width: 192rpx;
						text-align: center;
						color: #666666;
						border: 2rpx solid #FCF7F7;

						.lower {
							width: 42rpx;
							height: 42rpx;
							position: absolute;
							top: 50%;
							transform: translateY(-50%);
							right: 10rpx;
						}
					}
				}
			}

			.iptBox {
				display: flex;

				.ipt {
					box-sizing: border-box;
					width: 75%;
					height: 66rpx;
					padding-left: 75rpx;
					border: 2rpx solid #FCF7F7;
					border-radius: 10rpx;
				}

				.iptPla {
					height: 66rpx;
					line-height: 66rpx;
					color: #999;
					font-size: 22rpx;
				}

				.searchBtn {
					display: inline-block;
					background: #A6A6A6;
					width: 25%;
					height: 66rpx;
					line-height: 66rpx;
					text-align: center;
					border-radius: 10rpx;
					margin-left: 20rpx;
					font-size: 24rpx;
				}
			}
		}

		.list {
			width: 90%;
			margin-left: 5%;
			margin-top: 20rpx;
		}

		.list-box {
			width: 100%;
			height: 480rpx;
			border-radius: 5px;
			background: #F5F5F5;
			margin-bottom: 30rpx;
			padding: 20rpx 5%;
		}

		.item {
			display: flex;
			align-items: center;
			padding: 0 35rpx 0 19rpx;
			width: 100%;
			height: 78rpx;
			line-height: 78rpx;
			border-radius: 10rpx;
			border: 2rpx solid #FCF7F7;
			margin-top: 20rpx;

			.label {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				margin-right: 70rpx;
				width: 140rpx;
			}

			.ipt {
				flex: 1;
				position: relative;
				display: flex;
				align-items: center;
				color: #666;
			}
		}
	}
</style>